package com.meixiang.adapter.myFundAdapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.recyclerview.RecyclerAdapter;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by xyj on 2016/6/2.
 */
public class ScreenDataAdapter extends RecyclerAdapter<ScreenDataAdapter.ViewHolder> {
    private Context mContext;
    private int selectIndex = 0;
    private String[] screenData;
    public ScreenDataAdapter(Context context, String[] screenData) {
        this.mContext = context;
        this.screenData = screenData;
    }

    public void setSelectedIndex(int selectIndex){
        this.selectIndex = selectIndex ;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_fund_optional_screen_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        for (int i = 0; i < screenData.length; i++) {
            holder.tv_screen_describe.setText(screenData[position]);
            if(selectIndex == position){
                holder.iv_screen_selected_mark.setImageResource(R.mipmap.pitchon);
                holder.tv_screen_describe.setTextColor(ContextCompat.getColor(mContext,R.color.fund_money_color));
            }else{
                holder.iv_screen_selected_mark.setImageResource(0);
                holder.tv_screen_describe.setTextColor(ContextCompat.getColor(mContext,R.color.black_9));
            }
        }
    }

    @Override
    public int getItemCount() {
        return screenData.length;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_screen_describe)
        TextView tv_screen_describe;
        @Bind(R.id.iv_screen_selected_mark)
        ImageView iv_screen_selected_mark;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}